package ch10.shili;

public class S05_WorkThread  extends Thread{

    @Override
    public void run() {
        Thread t = Thread.currentThread();
        System.out.println("线程:" +t.getName()+" 正在运行");
        System.out.println(t.getName()+"开始摘苹果");
        for(int i = 0; i < 5; i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+" 进度: 第" + (i+1)+"棵");
        }
        System.out.println(t.getName()+"已经完成采摘任务");
    }

    public static void main(String[] args) throws InterruptedException {
        //新建状态 就绪状态 运行状态 阻塞状态 死亡状态
//        System.out.println("111111");
//        Thread.sleep(10000);
//        System.out.println("222222");
    }
}

class S05_ThreadTest{

    public static void main(String[] args) {
        S05_WorkThread t1 = new S05_WorkThread();
        t1.setName("果农E");
        System.out.println("线程:" +t1.getName()+" 已创建");
        t1.start();
        System.out.println("线程:" +t1.getName()+" 已就绪！");
    }

}
